﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using myproject_ria_iti.Web;

namespace myproject_ria_iti
{
    public partial class ManageItems : Page
    {
        DomainServiceInv Inv;
        public ManageItems()
        {
            InitializeComponent();
            Inv.Load<Item>(Inv.GetItemsQuery(), i =>
                {
                    listBoxItems.DataContext = Inv.Items;
                    gridItems.DataContext = Inv.Items.First<Item>();
                }, null);

            Inv.Load<Supplier>(Inv.GetSuppliersQuery(), i =>
            {
            
            }, null);
           
        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
        }

        private void itemDomainDataSource_LoadedData(object sender, LoadedDataEventArgs e)
        {

            if (e.HasError)
            {
                System.Windows.MessageBox.Show(e.Error.ToString(), "Load Error", System.Windows.MessageBoxButton.OK);
                e.MarkErrorAsHandled();
            }
        }

        private void listBoxItems_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            gridItems.DataContext = (Item)listBoxItems.SelectedItem;
        }

    }
}
